<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="48">
          <a-col :md="6" :sm="24">
            <a-form-item label="组织名称">
              <a-input v-model="queryParam.stdGroupName" placeholder="" />
            </a-form-item>
          </a-col>

          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item label="加入时间">
              <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="queryParam.joinTime_begin"></j-date>
              <span class="query-group-split-cust"></span>
              <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="queryParam.joinTime_end"></j-date>
            </a-form-item>
          </a-col>

          <a-col :md="(!advanced && 6) || 24" :sm="24">
            <span
              class="table-page-search-submitButtons"
              :style="(advanced && { float: 'right', overflow: 'hidden' }) || {}"
            >
              <a-button type="primary" @click="searchQuery">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
             
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus" v-has="'Organization:add'">新增</a-button>
      
      <a-button type="primary" icon="download" @click="handleExportXls('学生组织成员')" v-has="'Organization:edit'">导出</a-button>
      <a-button type="primary" icon="import" @click="visibleImport=true" v-has="'Organization:edit'">导入</a-button>
      <XImport v-model="visibleImport" moduleName="orgStdGroupUser" @ok="searchQuery" @cancel="visibleImport=false"></XImport>

      <a-dropdown v-if="selectedRowKeys.length > 0"  v-has="'Organization:batchdelete'">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel" v-has="'Organization:batchdelete'"><a-icon type="delete"/>批量删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <s-table ref="table" size="default" :scroll="{x:true}"  :columns="columns" :data="getData" @onSelect="onChange">
      <span slot="action" slot-scope="text, record">
        <a @click="handleReview(record)">查看</a>
        <a href="javascript:;" style="margin-left:10px" v-if="record.isDirector" @click="handleEmployment(record)">查看任职</a>
        <a @click="handleEdit(record)" style="margin-left:10px" v-has="record.isDirector?'Force':'Organization:edit'">编辑</a>
        <a-popconfirm v-has="record.isDirector?'Force':'Organization:delete'" style="margin-left:10px" title="确定删除?" @confirm="() => handleDelete(record.id)">
          <a>删除</a>
        </a-popconfirm>
        <a style="margin-left:10px" @click="handleDeal(record)"  v-if="record.dealFlag">审核</a>
      </span>
    </s-table>
    <!-- 学生组织成员弹窗 -->
    <OrganizationMemberModal ref="OrganizationMemberModal" @ok="searchQuery"></OrganizationMemberModal>

    <!-- 任职历史 -->
    <UserDepartRolesModal ref="UserDepartRolesModal"></UserDepartRolesModal>
  </a-card>
</template>

<script>
import STable from '@/components/table/'
import ATextarea from 'ant-design-vue/es/input/TextArea'
import AInput from 'ant-design-vue/es/input/Input'
import UserDepartRolesModal from '@/views/system/modules/UserDepartRolesModal'
import moment from 'moment'
import axios from 'axios'
import XImport from '@/components/extends/XImport.vue'
import JDate from '@/components/jeecg/JDate.vue'
import { getOrganizationMemberList,delOrganizationMember } from '@/api/api'
import { getAction, postAction, deleteAction } from '@/api/manage'
import OrganizationMemberModal from './modules/OrganizationMemberModal'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
export default {
  name: 'OrganizationMemberList',
  components: {
    AInput,
    ATextarea,
    STable,
    XImport,
    JDate,
    UserDepartRolesModal,
    OrganizationMemberModal
  },
  mixins:[JeecgListMixin,DisabledAuthFilterMixin],
  data() {
    return {
      visibleImport:false,
      disableMixinCreated:true,
      shenpi:false,
      form: null,
      mdl: {},
      url:{
        list:'/org/stdGroupUser/list',
        add:'/org/stdGroupUser/add',
        edit:'/org/stdGroupUser/edit',
        delete:'/org/stdGroupUser/delete',
        deleteBatch:'/org/stdGroupUser/deleteBatch',
        exportXlsUrl:'/org/stdGroupUser/exportXls',
      },
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      queryParam: {
        actStatus:10
      },
      // 表头
      columns: [
        {
          title: '组织名称',
          align:"center",
          width: 220,
          dataIndex: 'stdGroupName'
        },
        {
          title: '成员姓名',
          align:"center",
          width: 150,
          dataIndex: 'realname'
        },
        {
          title: '学院',
          align: "center",
          width: 150,
          dataIndex: 'college'
        },
        {
          title: '专业',
          align: 'center',
          width: 150,
          dataIndex: 'major'
        },
        {
          title: '年级',
          align: "center",
          width: 150,
          dataIndex: 'grade'
        },
        {
          title: '班级',
          align: "center",
          width: 150,
          dataIndex: 'clazz'
        },
        {
          title: '加入时间',
          align:"center",
          width:150,
          dataIndex: 'joinTime'
        },
        {
          title: '离开时间',
          align:"center",
          width:150,
          dataIndex: 'leaveTime'
        },
        {
          title: '操作',
          align:"center",
          // dataIndex: 'action',
          fixed:"right",
          width: 220,
          scopedSlots: { customRender: 'action' }
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      getData: parameter => {
        let params = Object.assign({},parameter, this.queryParam)
        // params.stdGroupName&&(params.stdGroupName = `*${params.stdGroupName}*`)
        return getAction(this.url.list, params).then(res => {
          if(res.success&&res.result){
            const obj = {
              data: res.result.records||[],
              pageNo: res.result.current,
              pageSize: res.result.size,
              totalCount: res.result.total,
              totalPage: res.result.page,
              sortColumns: res.result.sortColumns
            }
            return obj
          }else{
            return {}
          }
        })
      },
      selectedRowKeys: [],
      selectedRows: []
    }
  },
  created() {},
  methods: {
    // 添加
    handleAdd(){
      this.$refs.OrganizationMemberModal.add();
    },
    // 编辑
    handleEdit(record){
      this.$refs.OrganizationMemberModal.edit(record);
    },
    // 查看
    handleReview(record){
      this.$refs.OrganizationMemberModal.review(record);
    },
    // 删除
    handleDelete(id){
      delOrganizationMember({id}).then(res =>{
          if(res.success){
            this.$message.success('删除成功');
            this.searchQuery()
          }else{
            this.$message.error(res.message)
          }
      })
    },
    searchReset() {
      this.queryParam = {
        actStatus:10
      }
      this.searchQuery();
    },
    searchQuery(){
      this.$nextTick(()=>{
        this.$refs.table.refresh()
      })
    },
    onChange(row) {
      this.selectedRowKeys = row.selectedRowKeys
      this.selectedRows = row.selectedRows
    },
    toggleAdvanced() {
      this.advanced = !this.advanced
    },

    resetSearchForm() {
      this.queryParam = {
        date: moment(new Date())
      }
    },
    handleEmployment(record,orgCode){
      this.$refs.UserDepartRolesModal.queryParam.userId = record.userId
      this.$refs.UserDepartRolesModal.queryParam.userName = record.realname
      this.$refs.UserDepartRolesModal.queryParam.category = 'org_std_group'
      this.$refs.UserDepartRolesModal.visible =true
      this.$refs.UserDepartRolesModal.searchQuery()
    },
  },
  watch: {
  }
}
</script>
